require("glon")
GM.CV_ConfigPath = CreateConVar("space_conflict_config_path", "space_conflict_config.txt")

GM.ShipHulls = {}
GM.Parts = {}

function GM:LoadConfig()
	if not file.Exists(GM.CV_ConfigPath:GetString()) then
		file.Write(GM.CV_ConfigPath:GetString(), glon.encode({}))
		if not file.Exists(GM.CV_ConfigPath:GetString()) then
			ErrorNoHalt(string.format("Invalid value for space_conflict_config_path (%q).\n", GM.CV_ConfigPath:GetString()))
			RunConsoleCommand("space_conflict_config_path", "space_conflict_config.txt")
			GM:LoadConfig()
			return
		end
	end
	local contents = file.Read(GM.CV_ConfigPath:GetString())
	if #contents < 2 then
		Msg("Empty config file. Using and saving defaults.\n")
		GM:LoadDefaultConfig()
		GM:SaveConfig()
		return
	end
	local h_a, h_b, h_c = debug.gethook()
	debug.sethook()
	local worked, data = pcall(glon.decode, contents)
	debug.sethook(h_a, h_b, h_b)
	if not worked then
		ErrorNoHalt("Invalid config file. Using defaults.\n")
		GM.InvalidConfigFile = true
		GM:LoadDefaultConfig()
		return
	end
	
